package com.wuze.cloud.adapter;

import com.wuze.cloud.dao.SysUserDao;
import com.wuze.cloud.pojo.SysStorageDO;
import com.wuze.cloud.pojo.SysUserDO;
import com.wuze.cloud.response.SysStorageInfoAdminVO;
import com.wuze.cloud.response.SysStorageInfoVO;
import org.assertj.core.util.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: wuze
 * @description:
 * @date: 2023/02/28
 */
@Component
public class SysStorageAdapter {

    @Autowired
    private SysUserDao userDao;

    public SysStorageInfoVO buildSysStorageInfoVO(SysStorageDO storage){
        SysStorageInfoVO vo = new SysStorageInfoVO();
        BeanUtils.copyProperties(storage,vo);
        vo.setResidueSize(storage.getMaxSize()-storage.getCurrSize());
        return vo;
    }

    public SysStorageInfoAdminVO buildSysStorageInfoAdminVO(SysStorageDO storage){
        SysStorageInfoAdminVO vo = new SysStorageInfoAdminVO();
        SysUserDO user = userDao.findByIdV2(storage.getUserId());
        BeanUtils.copyProperties(storage,vo);
        vo.setUserName(user.getUserName());
        return vo;
    }

    public List<SysStorageInfoAdminVO> buildSysStorageInfoAdminVO(List<SysStorageDO> storages){
        List<SysStorageInfoAdminVO> vos = Lists.newArrayList();
        storages.forEach(storage->{
            vos.add(buildSysStorageInfoAdminVO(storage));
        });
        return vos;
    }

}
